package cn.itcast.nems.base.web.controller.o;


import cn.itcast.ic.common.bean.Page;
import cn.itcast.nems.base.api.SchoolApi;
import cn.itcast.nems.base.dto.SchoolDTO;
import cn.itcast.nems.base.dto.SchoolQueryDTO;
import cn.itcast.nems.common.PageQueryModel;
import cn.itcast.nems.common.web.vo.BasePageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 校区
 * </p>
 *
 * @author zhouwei
 * @since 2023/9/5 4:59 PM
 **/
@RestController
@RequestMapping("/o/school")
public class SchoolController {
    @Autowired
    private SchoolApi schoolApi;

    @PostMapping("/page/list")
    public ResponseEntity<?> findPageList(@RequestBody BasePageRequest<SchoolQueryDTO> queryParam) {
        queryParam.convert();
        SchoolQueryDTO queryDTO = Objects.nonNull(queryParam.getCondition()) ? queryParam.getCondition(): new SchoolQueryDTO() ;
        queryParam.setCondition(queryDTO);
        PageQueryModel<SchoolQueryDTO> queryModel =new PageQueryModel<>(queryParam.getPageNumber(), queryParam.getPageSize() , queryDTO) ;
        Page<SchoolDTO>  page  =   schoolApi.findPageList(queryModel) ;
        return ResponseEntity.ok().body(page) ;
    }

    /**
     * 获取校区列表
     *
     * @return 响应正文
     */
    @RequestMapping("/list")
    public ResponseEntity<?> list() {
        List<?> list = schoolApi.getAllSchool();
        return ResponseEntity.ok().body(list);
    }

}
